package com.nyist.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Repository;

import static org.elasticsearch.index.query.QueryBuilders.*;

import com.nyist.entity.User;

@Repository
public class CustomUserRepositoryImpl implements CustomUserRepository{

	  @Autowired
	  private ElasticsearchTemplate template;
	
	  public List<User> findByAgeWithRangeFilter(int start, int end) {
		    SearchQuery query = new NativeSearchQueryBuilder()
					       .withFilter(rangeQuery("age").gte(start).lte(end))
					       .build();
		    return template.queryForList(query,User.class);
	  }
	  
	  public List<User> findAll() {
		  SearchQuery query = new NativeSearchQueryBuilder()
				  .build();
		  return template.queryForList(query, User.class);
	  }
}
